module.exports = function($scope, getDate, groupcountlist){

    $scope.searchform = {};
    $scope.total = {};
    
    $scope.date = {
        'lable': getDate(new Date()),
        'opened': false
    }
    $scope.date1 = {
        'lable': getDate(new Date()),
        'opened': false
    }

    $scope.dateOpen = function($event, item){
        $event.preventDefault();
        $event.stopPropagation();
        item.opened = true;
    };


    $scope.load = function(){
        $scope.searchform.start = getDate($scope.date.lable);
        $scope.searchform.end = getDate($scope.date1.lable);

        $scope.total.book_count = 0;
        $scope.total.actual_count = 0;
        $scope.total.total = 0;

        groupcountlist.save($scope.searchform, function(res){
            if(res.errcode === 0) {
                $scope.objs = res.data;
                for(var i = 0, j = res.data.length; i < j; i++) {
                    $scope.total.book_count += parseInt(res.data[i].book_count);
                    $scope.total.actual_count += parseInt(res.data[i].actual_count);
                    $scope.total.total += parseInt(res.data[i].book_count * res.data[i].cost_price);
                }
            } else {
                alert(res.errmsg);
            }
        });
    };
    $scope.load();

    
    

};